function createWebSocketConnection(){
	ws = new WebSocket("ws://localhost:8080/playground/WebSocketServlet/login");
	ws.onopen = function(event) {
		console.log("connection opened");
	};
	
	ws.onmessage = function(event) {
		//console.log("message received");
		var data = jQuery.parseJSON(event.data);
		if (data.success){
			$.cookie("playerId", data.playerId);
			$.cookie("playerKey", data.playerKey);
			console.log("login succeeded " + data.playerId + " " + data.playerKey);
			console.log("playerId: " + $.cookie("playerId") + "; playerKey: " + $.cookie("playerKey"));
			ws.close();
			window.location.replace("gamehub.html");
		} else{
			console.log("login failed");
		}
	};
		
	ws.onclose = function(event) {
		console.log("connection closed");
	};
}

function login() {
	var message = $('#email').val();
	ws.send(message);
	console.log("message sent: " + message);
}